﻿
@using MvcForum.Core.Constants
@using MvcForum.Web.Application.ExtensionMethods
@model MvcForum.Web.Areas.Admin.ViewModels.LanguageListResourcesViewModel
@{
    ViewBag.Title = string.Concat("Resources for ", Model.LanguageName);
}
@Html.Partial("_LanguageOptions")

<div class="panel">
    <div class="panel-heading">
        <h5>@ViewBag.Title</h5>
    </div>
    <div class="panel-content">
        @using (Html.BeginForm("ManageLanguageResourceValues", "AdminLanguage", FormMethod.Post))
        {
            <div class="input-group tablesearch">
                @Html.TextBoxFor(x => Model.Search, new { @class = "form-control" })
                <span class="input-group-btn">
                    <button class="btn btn-default" type="submit">Search Values</button>
                </span>
            </div>
            @Html.HiddenFor(x => x.PageIndex)
            @Html.HiddenFor(x => x.LanguageId)
        }
        @using (Html.BeginForm("ManageLanguageResourceKeys", "AdminLanguage", FormMethod.Post))
        {
            <div class="input-group tablesearch">
                @Html.TextBoxFor(x => Model.Search, new { @class = "form-control" })
                <span class="input-group-btn">
                    <button class="btn btn-default" type="submit">Search Keys</button>
                </span>
            </div>
            @Html.HiddenFor(x => x.PageIndex)
            @Html.HiddenFor(x => x.LanguageId)
        }
        <table class="table table-bordered table-striped">
            <thead>
                <tr>
                    <th style="width: 65px;">
                        Edit
                    </th>
                    <th style="width: 180px;">
                        Resource Name
                    </th>
                    <th style="width: auto;">
                        Resource value
                    </th>
                </tr>
            </thead>
            <tbody>
                @foreach (var resource in Model.LocaleResources)
                {
                    <tr>
                        <td class="languageresourcecell">
                            <span class="editresource">
                                <a href="#" class="btn-mvc">
                                    <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
                                </a>
                            </span>
                            <span class="saveresource" style="display: none;">
                                <a href="#" class="btn-mvc">
                                    <span class="glyphicon glyphicon-ok" aria-hidden="true"></span>
                                </a>
                            </span>
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => resource.LocaleResourceKey)
                        </td>
                        <td class="resourcevalue">
                            <strong>
                                <span class="resourcevaluedisplay">
                                    @Html.DisplayFor(modelItem => resource.ResourceValue)
                                </span>
                                <span class="resourcevalueedit form-group" style="display: none;">
                                    <textarea data-languageid="@Model.LanguageId" style="width: 100%;"
                                              data-resourcekey="@resource.LocaleResourceKey"
                                              data-oldvalue="@resource.ResourceValue"
                                              id="@resource.ResourceKeyId"
                                              class="resourcevalueinput form-control">@resource.ResourceValue.Trim()</textarea>
                                </span>
                            </strong>
                        </td>
                    </tr>
                }
            </tbody>
        </table>

        @if (Model.TotalPages > 1)
        {
            @Html.Pager(Convert.ToInt32(Model.PageIndex), SiteConstants.Instance.AdminListPageSize, Convert.ToInt32(Model.TotalCount), new { languageId = Model.LanguageId, search = Model.Search })
        }


    </div>
</div>